<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.style4 {
	font-size: 24px;
	color: #000000;
}
.style5 {color: #000000}
-->
</style>
<?php
	include ("sql.inc.php");
	include ("../header.php");
	
	$sub		=	$_GET['sub'];
	$dep		=	$_GET['dep'];
	$sem		=	$_GET['sem'];
	$class		=	$_GET['class'];
	$qnum		=	$_GET['qnum'];
	$course		= 	$_GET['course'];
	
	//Protect data passing from SQL injection
	
	$sub = clean($sub);
	$dep = clean($dep);
	$sem	=	clean($sem);
	$class = clean($class);
	$qnum= clean($qnum);
	$course= clean($course);
	
	$sql_get_quest="SELECT * FROM quiz_question WHERE quiz_subject='$sub' AND quiz_department='$dep' AND quiz_course='$course'
					   AND quiz_sem='$sem' AND quiz_class='$class' AND quiz_number='$qnum'";
	$get_quest=mysql_query($sql_get_quest);
	$q=mysql_num_rows($get_quest);
	
	$count = 1;
	while ($count <=$q)
	{	
		if (!(isset($_POST['answer_'.$count.'']))){
			$answer[$count]=1;
		} else {
			$answer[$count] = $_POST['answer_'.$count.''];
		}
		$count++;
	}
	
	$count = 1;
	$marking=0;
	while ($count <= $q)
	{	
		$aid = $answer[$count];
		$sql_get_point="SELECT point FROM quiz_answer WHERE id='$aid'";
		$get_point=mysql_query($sql_get_point);
		$result=mysql_fetch_assoc($get_point);
		$point=$result['point'];
		$marking=$marking+$point;
		$count++;
	}

	//fetch student data from 
	$sql_get_student="SELECT * FROM student WHERE stud_no='$id'";
	$get_student=mysql_query($sql_get_student);
	$student_data=mysql_fetch_assoc($get_student);
	
?>
<table width="780" border="0" align="center">
  <tr>
    <td colspan="3" bgcolor="#999999"><span class="style1">MARKING SECTION</span></td>
  </tr>
  <tr valign="top">
    <td width="278">&nbsp;</td>
    <td width="14">&nbsp;</td>
    <td width="969">&nbsp;</td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Student Name </span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5">
      <?php $uname=$student_data['stud_name'];echo $uname; ?>
    </span></td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Student ID Number </span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5">
      <?php $sid=$student_data['stud_no'];echo $sid; ?>
    </span></td>
  </tr>
  <tr valign="top">
    <td colspan="3"><span class="style5"></span></td>
  </tr>
  <tr valign="top">
    <td colspan="3"><hr></td>
  </tr>
  <tr valign="top">
    <td colspan="3"><span class="style5"></span></td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Department</span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5"><?php echo $dep; ?></span></td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Subject</span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5"><?php echo $sub; ?></span></td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Class</span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5"><?php echo "{$course} {$sem}{$class}"; ?></span></td>
  </tr>
  <tr valign="top">
    <td><span class="style5">Quiz Number</span></td>
    <td><span class="style5">:</span></td>
    <td><span class="style5"><?php echo $qnum; ?></span></td>
  </tr>
  <tr>
    <td><span class="style5"></span></td>
    <td><span class="style5"></span></td>
    <td><span class="style5"></span></td>
  </tr>
  <tr>
    <td colspan="3"><hr></td>
  </tr>
  <tr>
    <td><span class="style5"></span></td>
    <td><span class="style5"></span></td>
    <td><span class="style5"></span></td>
  </tr>
  <tr valign="top">
    <td><span class="style4">Total Marks</span> </td>
    <td><span class="style5"></span></td>
    <td valign="top"><span class="style5"><?php echo "<font size=\"5px\" color=\"red\">".$marking."/{$q}"; ?></span></td>
  </tr>
  <tr valign="top">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr valign="top">
    <td colspan="3" bgcolor="#999999">&nbsp;</td>
  </tr>
</table>
<br>
<?php 
	$marking="{$marking}/{$q}";
	//INSERT DATA INTO DATABASE
	$sql_insert_mark="INSERT INTO mark (stud_id,subject,course,sem,class,quiz_num,marks) VALUES('$sid','$sub','$course','$sem','$class','$qnum','$marking')";
	$insert_mark=mysql_query($sql_insert_mark);
?>

<?php include("../footer.php"); ?>